#include "Game.h"
#include "SDL.h"
#include "SDL_Image.h"
#include "Screen.h"
#include "GameState.h"
#include "Timer.h"
#include "EventPoller.h"
#include "ReportError.h"
#include "PlayState.h"



#include <cassert>

Game::Game()
{
	m_running = true;
	m_currentState = 0;
	//m_tempAutoVec.reserve(1000);
}
Game::~Game()
{
	TheCamera::Kill();
	TheCar::Kill();
	TheEventPoller::Kill();
	ThePlayState::Kill();
	TheScreen::Kill();
	SDL_Quit();
}

void Game::Run()
{
	m_currentState  = ThePlayState::Instance();

	TheEventPoller::Instance()->AddHandler(this);


	//if(!Load("file.txt"))
	//{
	//	ReportError("Could not load file");
	//}
	//Load("file.txt");
    SDL_EnableKeyRepeat(500,30);
	while(m_running)
	{
		Update();
		Draw();
		TheScreen::Instance()->Flip();
	}
	ThePlayState::Instance()->CleanUp();
}

//bool Game::Load(const std::string &filename)
//{
//
//	return true;
//}

void Game::Update()
{	
	//ActualChangeofState();
	TheEventPoller::Instance()->Update();
	TheTimer::Instance()->Update();
	m_currentState->Update();
}

void Game::Draw()
{
	m_currentState->Draw();
}
